/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 07 - 08
 * Time: 10:20
 */
class Solution1 {
    public int countCharacters(String[] words, String chars) {
        int l = 0;
        int sum = 0;
        int k = 0;
        while(k < words.length) {
            l = 0;
            char[] arr = chars.toCharArray();
            for(int i = 0; i < words[k].length(); i++) {
                for(int j = 0; j < arr.length; j++) {
                    if(words[k].charAt(i) == arr[j]) {
                        l++;
                        arr[j] = 0;
                        break;
                    }
                }
            }
            if(l == words[k].length()) {
                sum += l;
            }
            k++;
        }
        return sum;
    }
}


